package com.longchat.service.impl.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.longchat.domain.permission.SysUser;
import com.longchat.dto.comm.DatatablesPageViewInfo;
import com.longchat.dto.comm.ResultInfo;
import com.longchat.dto.system.LoginInfo;
import com.longchat.dto.system.SysUserQueryInfo;
import com.longchat.query.SysUserQuery;
import com.longchat.repository.SysUserJpaRepository;
import com.longchat.service.inter.system.ISysuserService;
import com.longchat.utils.vo.ResultWrapper;

@Service
public class SysUserService implements ISysuserService {

	@Autowired
	private SysUserJpaRepository sysUserJpaRepository;
	@Autowired
	private SysUserQuery sysUserQuery;
	@Override
	public SysUser login(LoginInfo info) {
		return sysUserJpaRepository.findByUserNameAndPassword(info.getUserName(),info.getPassword());
	}
	
	@Override
	public ResultWrapper<SysUser> saveUser(SysUser user) {
		sysUserJpaRepository.save(user);
		return new ResultWrapper<SysUser>().OKWithData(user);
	}

	@Override
	public DatatablesPageViewInfo<SysUser> queryPageBy(SysUserQueryInfo info) {
		int count = sysUserQuery.findUsersCountBy(info);
	    return new DatatablesPageViewInfo<SysUser>(sysUserQuery.findUsersBy(info),count,count);
	}

	@Override
	public ResultInfo cancelUser(String uid) {
		return null;
	}

}
